package com.mxl.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author MXL
 * @date 2021/10/12
 **/
@Configuration
public class JavaBoyConfig {

    public static final String JAVABOY_QUEUE_NAME = "queue-javaboy";
    public static final String JAVABOY_EXCHANGE_NAME = "exchage-javaboy";

    @Bean
    Queue javaBoyQueue(){
        return new Queue(JAVABOY_QUEUE_NAME, true);
    }

    @Bean
    DirectExchange javaBoyExchange(){
        return new DirectExchange(JAVABOY_EXCHANGE_NAME);
    }

    /**
     * 绑定  队列 到 交换机 并使用 routerKey
     *
     * @return
     */
    @Bean
    Binding binding() {
        return BindingBuilder.bind(javaBoyQueue()).to(javaBoyExchange()).with(JAVABOY_QUEUE_NAME);
    }
}
